package server;

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class Client {

	private Client() {}

	public static void main(String[] args) {

		String host = (args.length < 1) ? null : args[0];
		try {
			Registry registry = LocateRegistry.getRegistry(host);
			FirewallManager stub = (FirewallManager)
			registry.lookup("FirewallManager");
			FirewallSession session = stub.login("FW_E", "1");
			if (session.isExpert()) {
				System.out.println("Woohoo! I'm an expert\n");
			} else {
				System.out.println("Oh man, I'm simple!\n");
			}
			Protocol proto = new Protocol("HTTP", "test", "ing");
			session.updateProtocol(proto);
			session.deleteProtocol("HTTP");
			proto = new Protocol("HTTP", "http/(0\\.9|1\\.0|1\\.1) [1-5][0-9][0-9] [\\x09-\\x0d -~]*(connection:|content-type:|content-length:|date:)|post [\\x09-\\x0d -~]* http/[01]\\.[019]", "get .* http/[01]\\.[019]");
			session.addProtocol(proto);
			Protocol[] protolist = session.getProtocols();
			for (Protocol protol : protolist)
				System.out.println(protol.protocol + ": " + protol.inReg + " : " + protol.outReg);
			Rule rule = new Rule(1, "127.0.0.1", 66, Rule.permissionOpt.ALLOW);
			session.addRule(RulesTableType.OUT, "default", rule);
			Thread.sleep(5000);
			session = null;
			System.gc();
			System.runFinalization();
		} catch (InvalidLoginException e) {
			System.out.println("Invalid username/password!\n");
		} catch (Exception e) {
			System.err.println("Client exception: " + e.toString());
			e.printStackTrace();
		}
	}
}
